package com.yykt.weshare.interceptor;

import com.yykt.weshare.Exception.AppException;
import com.yykt.weshare.enums.ResultEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@Slf4j
@Component
public class AdminInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        String url = request.getRequestURI();
        log.info("admin interceptor get url:{}", url);
        HttpSession session = request.getSession();
        if (session.getAttribute("user") == null) {
            throw new AppException(ResultEnum.USERNAME_PASSWORD_ERROR);
        }
        return true;
    }

}
